package zb.wzby;

import java.util.concurrent.TimeUnit;

/**
 * @author wzby
 * @Date: 2022/8/9 20:27
 */
public class VolatileDemo {
    volatile boolean f = true;
    void zb(){
        String s = Thread.currentThread().getName();
        System.out.printf("%s线程启动%n",s);
        while (f){

        }
        System.out.printf("%s线程关闭%n",s);
    }

    public static void main(String[] args) {
        var vd = new VolatileDemo();
        new Thread(vd::zb,"Vd1").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        }catch (Exception e){
            e.printStackTrace();
        }
        vd.f = false;
        System.out.println(vd.f);
    }
}
